package com.neihe.common.enums;

import com.neihe.common.constant.Const;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 分享日期类型枚举类
 */
@Getter
@AllArgsConstructor
public enum ShareDayTypeEnum {

    PERMANENT_VALIDITY(0, 0, "永久分享"),

    SEVEN_DAYS_VALIDITY(1, 7, "7天有效"),

    THIRTY_DAYS_VALIDITY(2, 30, "30天有效"),

    ONE_DAYS_VALIDITY(3, 1, "1天有效");

    private final Integer code;

    private final Integer days;

    private final String desc;

    /**
     * 根据穿过来的分享天数的code获取对应的分享天数的数值
     */
    public static Integer getShareDayByCode(Integer code) {
        if (code == null) {
            return Const.MINUS_ONE_INT;
        }

        for (ShareDayTypeEnum value : values()) {
            if (Objects.equals(value.getCode(), code)) {
                return value.getDays();
            }
        }
        return Const.MINUS_ONE_INT;
    }

    public static String getShareDescByCode(Integer code) {
        for (ShareDayTypeEnum value : values()) {
            if (Objects.equals(value.getCode(), code)) {
                return value.getDesc();
            }
        }
        return null;
    }

}
